home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cuj9205.zip / 1005074B < prev    next >
Text File  |  1992-06-02  |  423b  |  26 lines

  1. /*
  2.  *    Listing 2 -- Error by writing a freed pointer
  3.  *            (item's value may have changed)
  4.  */
  5.  
  6. #include <stdlib.h>
  7. #include <assert.h>
  8.  
  9. void    main() {
  10. int    *ip;
  11.  
  12.     /* allocate an integer */
  13.     ip = malloc(sizeof(int));
  14.     assert(ip != NULL);
  15.  
  16.     /* initialize the integer */
  17.     (*ip) = 1;
  18.  
  19.     /* deallocate the integer */
  20.     free(ip);
  21.  
  22.     /* update the deallocated integer */
  23.     (*ip)++;
  24.     printf("*ip == %d\n",*ip);
  25. }
  26.